<?php
/**
 * User:chendenan
 * Created On 2022/3/10 0010 23:25
 */

declare(strict_types=1);
namespace app\api\controller;

use app\BaseController;
use app\common\business\Sms as SmsBus;

class Sms extends  BaseController{
    public function code() :object{
        $phoneNumber = input("param.phone_number",'',"trim");
        $data = [
            'phone_number' => $phoneNumber
        ];
        try{
            validate(\app\api\validate\User::class)->scene('send_code')->check($data);
        }catch(\think\Exception\ValidateException $e){
            return show($e->getError(),config('status.error'));
        }
        //进行权重统计 利用随机数进行验证码分发
        $rand = rand(1,10);
        $type = $rand>=8?'ali':'dxw';
        $type = 'dxw';
        //调用business层的数据
        if(SmsBus::sendCode($phoneNumber,4,$type)){
            return show("发送验证码成功",config("status.success"));
        }
        return show("发送验证码失败",config("status.error"));
    }
}